<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>相册管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script src="/js/util.js"></script>
<style>

    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 150px;
        height: 70px;
        line-height: 150px;
        text-align: center;
    }

    .avatar {
        width: 150px;
        height: 70px;
        display: block;
    }

</style>


<body class="hold-transition">

<div id="app">
    <div class="content-header">
        <h1>管理
            <small>相册管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>brand管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-button type="primary" class="butT" @click="formVisible=true;pojo={}">新增</el-button>
                <el-table :data="imageUrls" border style="width: 100%">
                    <el-table-column
                            label="图片列表">
                        <template slot-scope="scope">
                            <img width="200px" height="200px" :src="scope.row.url">
                        </template>
                    </el-table-column>
                    <el-table-column
                            label="操作">
                        <template slot-scope="scope">
                            <el-button @click="dele()" size="mini" type="danger" size="small">删除</el-button>
                            <el-button @click="dele()" size="mini" type="primary" size="small">添加</el-button>
                        </template>
                    </el-table-column>

                </el-table>
                <div class="add-form">
                    <!--弹出窗口-->
                    <el-dialog title="编辑" :visible.sync="formVisible">
                        <el-form label-width="80px">
                            <el-form-item label="相册名称">
                                <el-input v-model="pojo.url"></el-input>
                            </el-form-item>
                            <el-form-item label="相册封面">
                                <el-input v-model="pojo.uid"></el-input>
                            </el-form-item>
                            <el-form-item label="图片列表">
                                <el-input v-model="pojo.status"></el-input>
                            </el-form-item>

                            <!-- 图片上传代码 如页面有图片上传功能放开注释 ****-->
                            <el-form-item label="图片">
                                <el-upload
                                        class="avatar-uploader"
                                        action="/upload/native.do"
                                        :show-file-list="false"
                                        :on-success="handleAvatarSuccess"
                                        :before-upload="beforeAvatarUpload">
                                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </el-form-item>


                            <el-form-item>
                                <el-button type="primary" @click="save()">保存</el-button>
                                <el-button @click="formVisible = false">关闭</el-button>
                            </el-form-item>
                        </el-form>
                    </el-dialog>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                tableData: {},
                id: 0,
                imageUrls: [],
                fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],
                imageUrl: '',
                pojo: {},
                formVisible: false

            }
        },
        created() {
            this.id = getQueryString("id");
            // alert(this.id);
            this.fetchData();
        },
        methods: {

            fetchData() {
                axios.get(`/album/findById.do?id=${this.id}`).then(response => {
                    // JSON.parse(response.data.imageItems);
                    // alert(response.data.imageItems);
                    /*this.imageUrls = */
                    this.imageUrls = JSON.parse(response.data.imageItems);
                })
            },
            save() {
                this.pojo.url = this.imageUrl;
                this.pojo.id=this.id;
                axios.post(`/album/addImages.do`, this.pojo).then(() => {
                    this.formVisible = false;//关闭窗口
                    this.fetchData(); //刷新列表
                })
            },









            /****图片上传相关代码  如页面有图片上传功能放开注释 **** */
            handleAvatarSuccess(res, file) {
                this.imageUrl = file.response;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            }


        }

    })

</script>
</html>